import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDRandomEvent {
	/**ID*/
	id,
	/**解锁关卡id*/
	unlockStage,
	/**解锁等级范围--数组[0]<=等级范围<=数组[1]*/
	unlockLevel,
	/**权重*/
	weight,
	/**事件类型--1.战斗buff【1.己方2敌方】【buffid】--2.掉落【掉落】【无意义】--3.立即刷新随机事件【无意义】【无意义】--4.流浪商人--5.收购商人（暂不处理）--6.特殊关卡【关卡id】【无意义】--7.小玩法-点击--8.特殊buff（暂不处理）--9.特殊任务（暂不处理）*/
	eventType,
	/**系数1*/
	param_1,
	/**系数2*/
	param_2,
	/**持续时间*/
	time,
	/**名称*/
	name,
	/**描述*/
	desc,
	/**每日限制次数*/
	dailyTimes,
	/**图标*/
	icon,
	/**特效--不填，表示没有特效*/
	effect,
	/**特效目标--1自身，2敌人，3全体友方（自身和宠物）*/
	target,
	/**飘字地点--1自身，2敌人，3战斗界面中央*/
	textTarget,
	/**飘字内容--不填，表示没有飘字*/
	text,
	/**飘字类型--0.普通1.增益2.负面*/
	textType,
	/**描述*/
	desc_2,

	/**枚举数量*/
	EnumCount
}



export class CDRandomEvent{
	/**ID*/
	public id: number;
	/**解锁关卡id*/
	public unlockStage: number;
	/**解锁等级范围--数组[0]<=等级范围<=数组[1]*/
	public unlockLevel: number[];
	/**权重*/
	public weight: number;
	/**事件类型--1.战斗buff【1.己方2敌方】【buffid】--2.掉落【掉落】【无意义】--3.立即刷新随机事件【无意义】【无意义】--4.流浪商人--5.收购商人（暂不处理）--6.特殊关卡【关卡id】【无意义】--7.小玩法-点击--8.特殊buff（暂不处理）--9.特殊任务（暂不处理）*/
	public eventType: number;
	/**系数1*/
	public param_1: number;
	/**系数2*/
	public param_2: number;
	/**持续时间*/
	public time: number;
	/**名称*/
	public name: number;
	/**描述*/
	public desc: number;
	/**每日限制次数*/
	public dailyTimes: number;
	/**图标*/
	public icon: string;
	/**特效--不填，表示没有特效*/
	public effect: string;
	/**特效目标--1自身，2敌人，3全体友方（自身和宠物）*/
	public target: number;
	/**飘字地点--1自身，2敌人，3战斗界面中央*/
	public textTarget: number;
	/**飘字内容--不填，表示没有飘字*/
	public text: number;
	/**飘字类型--0.普通1.增益2.负面*/
	public textType: number;
	/**描述*/
	public desc_2: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDRandomEvent.id: return this.id;
			case E_CDRandomEvent.unlockStage: return this.unlockStage;
			case E_CDRandomEvent.unlockLevel: return this.unlockLevel;
			case E_CDRandomEvent.weight: return this.weight;
			case E_CDRandomEvent.eventType: return this.eventType;
			case E_CDRandomEvent.param_1: return this.param_1;
			case E_CDRandomEvent.param_2: return this.param_2;
			case E_CDRandomEvent.time: return this.time;
			case E_CDRandomEvent.name: return this.name;
			case E_CDRandomEvent.desc: return this.desc;
			case E_CDRandomEvent.dailyTimes: return this.dailyTimes;
			case E_CDRandomEvent.icon: return this.icon;
			case E_CDRandomEvent.effect: return this.effect;
			case E_CDRandomEvent.target: return this.target;
			case E_CDRandomEvent.textTarget: return this.textTarget;
			case E_CDRandomEvent.text: return this.text;
			case E_CDRandomEvent.textType: return this.textType;
			case E_CDRandomEvent.desc_2: return this.desc_2;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDRandomEvent.id: this.id = v; break;
			case E_CDRandomEvent.unlockStage: this.unlockStage = v; break;
			case E_CDRandomEvent.unlockLevel: this.unlockLevel = v; break;
			case E_CDRandomEvent.weight: this.weight = v; break;
			case E_CDRandomEvent.eventType: this.eventType = v; break;
			case E_CDRandomEvent.param_1: this.param_1 = v; break;
			case E_CDRandomEvent.param_2: this.param_2 = v; break;
			case E_CDRandomEvent.time: this.time = v; break;
			case E_CDRandomEvent.name: this.name = v; break;
			case E_CDRandomEvent.desc: this.desc = v; break;
			case E_CDRandomEvent.dailyTimes: this.dailyTimes = v; break;
			case E_CDRandomEvent.icon: this.icon = v; break;
			case E_CDRandomEvent.effect: this.effect = v; break;
			case E_CDRandomEvent.target: this.target = v; break;
			case E_CDRandomEvent.textTarget: this.textTarget = v; break;
			case E_CDRandomEvent.text: this.text = v; break;
			case E_CDRandomEvent.textType: this.textType = v; break;
			case E_CDRandomEvent.desc_2: this.desc_2 = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDRandomEvent> = new HashMap<number, CDRandomEvent>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDRandomEvent[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDRandomEvent();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].unlockStage = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].unlockLevel = [];
			const attrArray = list[i].unlockLevel;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].weight = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].eventType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].param_1 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].param_2 = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].time = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].dailyTimes = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].effect = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].target = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].textTarget = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].text = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].textType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].desc_2 = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDRandomEvent{
		return this.datas ? this.datas.get(id) : null;
	}
}
